package com.itheima.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface ReportMapper {
    //拿到日期的最大值
    @Select("select max(regTime) from t_member")
    Date getMaxDate();
    //拿到日期的最小值
    @Select("select min(regTime) from t_member")
    Date getMinDate();
//    查询每月的会员数量
    @Select("select count(*) from t_member where regTime between #{minDateOfMonth} and #{maxDateOfMonth}")
    Integer getMemberCountByMonth(Date minDateOfMonth, Date maxDateOfMonth);

    /**
     * 从表中拿到所有的name
     * @return
     */
    @Select("select name from t_setmeal")
    List<String> getmealNames();

    /**
     * 根据name去查id被引用了几次
     * @param setmealName
     * @return
     */
    @Select("select count(*) from t_setmeal_checkgroup where setmeal_id = (select id from t_setmeal where name = #{setmealName})")
    Integer getSetmealIdByName(String setmealName);
    /**
     * 准备今日新增会员数
     */
    @Select("select count(*) from t_member where regTime between #{startDate} and #{endDate}")
    Integer getMemberCountByDay(Date startDate, Date endDate);
    /**
     * 本周新会员人数
     */
    @Select("select count(*) from t_member where regTime between #{firstDay3} and #{lastDay3}")
    Integer getMemberCountByWeek(Date firstDay3, Date lastDay3);
    /**
     * 会员总数
     */
    @Select("select count(*) from t_member")
    Integer getTotalMember();
    /**
     * 查询日期范围订单数量
     */
    @Select("select count(*) from t_order where orderDate between #{startDate} and #{endDate}")
    Integer getOrderNumber(Date startDate, Date endDate);

    /**
     * 根据日期范围查询t_order表orderStatus字段有几个是"到诊"
     * @param startDate
     * @param endDate
     * @return
     */
    @Select("select count(*) from t_order where orderDate between #{startDate} and #{endDate} and orderStatus = '已到诊'")
    Integer getVisitsNumber(Date startDate, Date endDate);
}
